#ifndef GAMEMODEL_H
#define GAMEMODEL_H

////////  激情五子棋  ////////

#include <vector>

#include <QJsonDocument>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonValue>   //headers about wenji

#include <QNetworkAccessManager>
#include <QNetworkReply>
#include <QNetworkRequest>
#include <QDebug>     //headers about network
//#include "mainwindow.h"
//gametype
enum GameType
{
    MAN,//play with friends in one computer
    AI ,//fight with computer
    net,//play with other people at internet
    watch//internet watch fighting
};

enum GameStatus //judge the status of game
{
    PLAYING,//ing
    WIN,//you win
    DEAD//you lose
};

//棋盤尺寸
const int BOARD_GRAD_SIZE = 15;//the
const int MARGIN = 30; //棋盘间隙
const int CHESS_RADIUS = 15; //棋子半径
const int MARK_SIZE = 6; //落子标记
const int BLOCK_SIZE = 40; //格子大小
const int POS_OFFSET = BLOCK_SIZE*0.4; //鼠标点击

const int AI_THINK_TIME = 100; //AI下棋思考時間

class GameModel
{
public:
    GameModel();
public:
    //黑色为1 白色为-1
    std::vector<std::vector<int>> gameMapVec;

    //储存棋盘的ai评分
    std::vector<std::vector<int>> scoreMapVec;

    //表示下棋方，true黑
    bool playerFlag;

    GameType gameType; //选择游戏模式

    GameStatus gameStatus; //当前游戏状态

    void startGame(GameType type);

    void actionByPerson(int row, int col);//由人来下棋
    void updateGameMap(int row, int col);//更新当前棋盘
    bool isWin(int row,int col);//判断是否有某一方获胜
    void calculateScore(); //计算分数

    void actionByAI(int &clickRow,int &clickCol); //ai下棋
    void actionBynet(int &clickRow,int &clickCol);

    QString userID;//用户申请的id号码
    QNetworkAccessManager * manager;//管理器
    QNetworkRequest request;//请求，可理解为与服务器的合同
};

#endif // GAMEMODEL_H
